home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-17 | 6.7 KB | 269 lines | [TEXT/KAHL] |
- /*****************************************************************
- "Palette.c"
-
- from the pioneering work by:
-
- Don Melton & Mike Ritter [MacTutor, April, 1988]
-
- as adapted by:
-
- John A. Love, III [Washington Apple Pi Users' Group]
-
- using Symantec's "THINK C", v 5.00
- *****************************************************************/
-
-
-
-
- // Prototypes:
-
- pascal long main (short variation, WindowPtr whichWindow, short message,
- long parameter);
- void DrawWindow (WindowPtr whichWindow, long parameter);
- long TestWindowHit (WindowPtr whichWindow, long parameter);
- void CalcWindowRegions (short variation, WindowPtr whichWindow);
-
-
- typedef struct QuickDraw {
- /* When allocated on the Stack,
- ** stored in reverse order: */
-
- char private[76]; // low memory.
- long randSeed;
- BitMap screenBits;
- Cursor arrow;
- Pattern dkGray, ltGray, gray, black, white;
- GrafPtr thePort; // High memory.
- } QuickDraw;
-
-
- #define PALETTE_TITLE_BAR_HEIGHT 10
- #define PALETTE_SHADOW_INDENT 2
-
-
-
- pascal long main (short variation, WindowPtr whichWindow, short message,
- long parameter) {
-
- long result = 0;
-
-
- if (message == wDraw) DrawWindow(whichWindow, parameter);
- else if (message == wHit) result = TestWindowHit(whichWindow, parameter);
- else if (message == wCalcRgns) CalcWindowRegions(variation, whichWindow);
-
- /* Ignore wNew & wDispose because we are using standard type windows.
- ** Ignore wGrow & wDrawGIcon because we are NOT using growable windows. */
-
- return (result);
-
- } /* main */
-
-
-
- void DrawWindow (WindowPtr whichWindow, long parameter) {
-
- WindowPeek whichPWindow;
- Boolean hasShadowFrame, hasTitleBar;
- Rect frame, goAway;
- PenState savePen;
- short tone, index;
- Pattern hilite;
- QuickDraw *qdGlobals;
-
-
- whichPWindow = (WindowPeek) whichWindow;
-
- if (whichPWindow->visible) {
-
- // Setup a pointer to QuickDraw's Globals:
- qdGlobals = (QuickDraw*)(*(Ptr*)CurrentA5 /* Ptr to thePort */ -
- (sizeof(QuickDraw) - sizeof(GrafPtr)) );
-
- hasShadowFrame = (*whichPWindow->strucRgn)->rgnBBox.right >
- (*whichPWindow->contRgn )->rgnBBox.right + 1;
- hasTitleBar = (*whichPWindow->contRgn )->rgnBBox.top ==
- (*whichPWindow->strucRgn)->rgnBBox.top + 1 +
- PALETTE_TITLE_BAR_HEIGHT;
-
- // Calculate the window frame:
-
- frame = (*whichPWindow->strucRgn)->rgnBBox;
-
- // Calculate the goAway box. We'll determine later IF it has one:
-
- goAway = frame;
- goAway.top += 2;
- goAway.left += 8;
- goAway.bottom = goAway.top + 7;
- goAway.right = goAway.left + 7;
-
- if (parameter) InvertRect(&goAway); /* = wInGoAway */
- else {
- // Draw window frame, drop shadow, title bar & goAway box:
-
- GetPenState(&savePen);
- PenNormal();
- ;
- if (hasShadowFrame) {
- frame.bottom -= 1;
- frame.right -= 1;
- }
- FrameRect(&frame);
-
- if (hasShadowFrame) {
- MoveTo(frame.left + PALETTE_SHADOW_INDENT, frame.bottom);
- LineTo(frame.right, frame.bottom);
- LineTo(frame.right, frame.top + PALETTE_SHADOW_INDENT);
- }
-
- if (hasTitleBar) {
- frame.bottom = frame.top + (PALETTE_TITLE_BAR_HEIGHT + 1);
- FrameRect(&frame);
- InsetRect(&frame, 1, 1);
-
- if (whichPWindow->hilited) {
-
- // Adjust pattern and fill title bar:
-
- tone = (frame.left & 1) ? 0x55 : 0xAA;
-
- for (index = 0; index <= 7; index++)
- hilite[index] = ((index + frame.top) & 1) ? tone : 0;
-
- FillRect(&frame, &hilite);
-
- // Draw goAway box:
-
- if (whichPWindow->goAwayFlag) {
- frame = goAway;
- InsetRect(&frame, -1, -1);
- EraseRect(&frame);
- FrameRect(&goAway);
- }
-
- } /* if hilited */
- else FillRect(&frame, qdGlobals->white);
- } /* has a Title Bar */
- ;
- SetPenState(&savePen);
-
- } /* if parameter == 0 */
-
- } /* if window is visible */
-
- } /* DrawWindow */
-
-
-
- long TestWindowHit (WindowPtr whichWindow, long parameter) {
-
- WindowPeek whichPWindow;
- Boolean hasShadowFrame, hasTitleBar;
- Point where;
- Rect drag, goAway;
-
-
- whichPWindow = (WindowPeek) whichWindow;
- hasShadowFrame = (*whichPWindow->strucRgn)->rgnBBox.right >
- (*whichPWindow->contRgn )->rgnBBox.right + 1;
- hasTitleBar = (*whichPWindow->contRgn )->rgnBBox.top ==
- (*whichPWindow->strucRgn)->rgnBBox.top + 1 +
- PALETTE_TITLE_BAR_HEIGHT;
-
- where.v = HiWord(parameter);
- where.h = LoWord(parameter);
-
- if ( PtInRect(where, &(*whichPWindow->contRgn)->rgnBBox) )
- return (wInContent);
-
- else if (hasTitleBar) {
- // Mouse in title bar somehere:
-
- drag = (*whichPWindow->strucRgn)->rgnBBox;
- InsetRect(&drag, 1, 1);
- if (hasShadowFrame) drag.right -= 1;
- drag.bottom = drag.top + (PALETTE_TITLE_BAR_HEIGHT - 1);
-
- if (PtInRect(where, & drag)) {
-
- if (whichPWindow->goAwayFlag) {
- goAway = drag;
- goAway.top += 1;
- goAway.left += 7;
- goAway.bottom = goAway.top + 7;
- goAway.right = goAway.left + 7;
-
- if ( whichPWindow->hilited && PtInRect(where, &goAway) )
- return (wInGoAway);
- else return (wInDrag);
- }
- else return (wInDrag);
-
- }
-
- } /* Mouse in title bar somehere */
-
- return (wNoHit);
-
- } /* TestWindowHit */
-
-
-
- void CalcWindowRegions (short variation, WindowPtr whichWindow) {
-
- WindowPeek whichPWindow;
- Boolean hasShadowFrame, hasTitleBar;
- Rect windowRect;
- RgnHandle shadowRgn;
-
-
- whichPWindow = (WindowPeek) whichWindow;
- hasShadowFrame = (variation == documentProc ) ||
- (variation == noGrowDocProc) ||
- (variation == altDBoxProc);
- hasTitleBar = (variation == documentProc ) ||
- (variation == noGrowDocProc) ||
- (variation == rDocProc);
-
- // Calculate content region of the window:
-
- windowRect = whichWindow->portRect;
- /* The window's BitMap, portBits, includes the Title Bar.
- ** So, we first expand the portRect and later bring it
- ** back to compute just the contRgn. */
- if (hasTitleBar) windowRect.top -= PALETTE_TITLE_BAR_HEIGHT;
- OffsetRect(&windowRect, /* LocalToGlobal */
- -whichWindow->portBits.bounds.left,
- -whichWindow->portBits.bounds.top);
- if (hasTitleBar) windowRect.top += PALETTE_TITLE_BAR_HEIGHT;
- RectRgn(whichPWindow->contRgn, &windowRect);
-
- /* Calculate structure region of the window:
- a) frame b) title bar c) shadow of frame */
-
- InsetRect(&windowRect, -1, -1);
- RectRgn(whichPWindow->strucRgn, &windowRect);
-
- if (hasTitleBar) {
- windowRect.top -= PALETTE_TITLE_BAR_HEIGHT;
- RectRgn(whichPWindow->strucRgn, &windowRect);
- }
-
- if (hasShadowFrame) {
- windowRect.top += PALETTE_SHADOW_INDENT;
- windowRect.left += PALETTE_SHADOW_INDENT;
- windowRect.bottom += 1; /* Width of the shadow = 1 */
- windowRect.right += 1;
- RectRgn(shadowRgn = NewRgn(), &windowRect);
- UnionRgn(whichPWindow->strucRgn, shadowRgn, whichPWindow->strucRgn);
- DisposeRgn(shadowRgn);
- }
-
- } /* CalcWindowRegions */
-
-
-
-
- /* { end file "Palette.c" } */
-